//basedata.js
//获取应用实例
var app = getApp()
Page({
  data:{
    baseDataList:null,
    userInfo: {},
    title:null,
    type:null
  },
  onLoad: function (options) {
    var that = this
    // console.log(app.globalData.recordParam)
    var memberTypeList = []
    var expenseTypeList = []
    var incomeTypeList = []
    var cardTypeList = []

    for (var i = 0; i < app.globalData.recordParam.member.length; i++) {
      memberTypeList[i]={"id":app.globalData.recordParam.member[i].id,"name":app.globalData.recordParam.member[i].member,"remark":app.globalData.recordParam.member[i].remark}
    }
    for (var i = 0; i < app.globalData.recordParam.patern.length; i++) {
      cardTypeList[i]={"id":app.globalData.recordParam.patern[i].id,"name":app.globalData.recordParam.patern[i].cardtype,"remark":app.globalData.recordParam.patern[i].remark}
    }
    for (var i = app.globalData.recordParam.kind.length-1; i >= 0; i--) {
      if (app.globalData.recordParam.kind[i].kind=='支出'){
        for (var j = app.globalData.recordParam.kind[i].type.length-1; j >= 0; j--) {
          expenseTypeList.splice(0,0,app.globalData.recordParam.kind[i].type[j]);
        }
      }else if(app.globalData.recordParam.kind[i].kind=='收入'){
        for (var j = app.globalData.recordParam.kind[i].type.length-1; j >= 0; j--) {
          incomeTypeList.splice(0,0,app.globalData.recordParam.kind[i].type[j]);
        }
      }
    }
    that.setData({
      userInfo:app.globalData.userInfo
    })
    switch(parseInt(options.id)){
      case 0:
        that.setData({
          title: '成员',
          baseDataList: memberTypeList,
          type:3
        })
        wx.setNavigationBarTitle({
          title: '成员'
        })
      break;
      case 1:
        that.setData({
          title: '支出类型',
          baseDataList: expenseTypeList,
          type:1
        })
        wx.setNavigationBarTitle({
          title: '支出类型'
        })
      break;
      case 2:
        that.setData({
          title: '收入类型',
          baseDataList: incomeTypeList,
          type:2
        })
        wx.setNavigationBarTitle({
          title: '收入类型'
        })
      break;
      case 3:
        cardTypeList.splice(0,1)
        that.setData({
          title: '卡种',
          baseDataList: cardTypeList,
          type:4
        })
        wx.setNavigationBarTitle({
          title: '卡种'
        })
      break;
      default:
      break
    }
  },
  baseItem: function (e){
    var that = this
    if(that.data.baseDataList[e.currentTarget.dataset.index].default){
      wx.showToast({
        title: '默认属性，无法修改',
        icon: 'success'
      })
    }else{
      wx.navigateTo({
        url: '/pages/smartlife/wangcai/setting/basedata/editdata/editdata?type='+that.data.type+'&id='+that.data.baseDataList[e.currentTarget.dataset.index].id+'&name='+that.data.baseDataList[e.currentTarget.dataset.index].name+'&remark='+that.data.baseDataList[e.currentTarget.dataset.index].remark
      })
    }
  },
  addRecordType: function (e){
    var that = this
    wx.navigateTo({
      url: '/pages/smartlife/wangcai/setting/basedata/editdata/editdata?type='+that.data.type
    })
  },
  memberData:function(e){
    var that=this
    var memberTypeList = []
    for (var i = 0; i < app.globalData.recordParam.member.length; i++) {
      memberTypeList[i]={"id":app.globalData.recordParam.member[i].id,"name":app.globalData.recordParam.member[i].member,"remark":app.globalData.recordParam.member[i].remark}
    }
    that.setData({
      baseDataList: memberTypeList
    })
  },
  expenseData:function(e){
    var that=this
    var expenseTypeList = []
    for (var i = app.globalData.recordParam.kind.length-1; i >= 0; i--) {
      if (app.globalData.recordParam.kind[i].kind=='支出'){
        for (var j = app.globalData.recordParam.kind[i].type.length-1; j >= 0; j--) {
          expenseTypeList.splice(0,0,app.globalData.recordParam.kind[i].type[j]);
        }
      }
    }
    that.setData({
      baseDataList: expenseTypeList
    })
  },
  incomeData:function(e){
    var that=this
    var incomeTypeList = []
    for (var i = app.globalData.recordParam.kind.length-1; i >= 0; i--) {
      if(app.globalData.recordParam.kind[i].kind=='收入'){
        for (var j = app.globalData.recordParam.kind[i].type.length-1; j >= 0; j--) {
          incomeTypeList.splice(0,0,app.globalData.recordParam.kind[i].type[j]);
        }
      }
    }
    that.setData({
      baseDataList: incomeTypeList
    })
  },
  cardtypeData:function(e){
    var that=this
    var cardTypeList = []
    for (var i = 0; i < app.globalData.recordParam.patern.length; i++) {
      cardTypeList[i]={"id":app.globalData.recordParam.patern[i].id,"name":app.globalData.recordParam.patern[i].cardtype,"remark":app.globalData.recordParam.patern[i].remark}
    }
    cardTypeList.splice(0,1)
    that.setData({
      baseDataList: cardTypeList
    })
  }
})